<?php

namespace app\api\service;
use app\common\model\Occupants;
use app\common\model\Rooms;
use think\Db;

error_reporting(E_ERROR);
class RoomService
{
    //判断人数够不够
    public function order_in($room_id,$shop_id,$start_time='',$end_time=''){
        if (empty($start_time) || empty($end_time)) {
            $current_time = date('Y-m-d H:i:s');
            $start_time = $current_time;
            $end_time = $current_time;
        }
        //正在游玩人数
        $incount=Occupants::where('id','=',$room_id)->where('status',0)->where('shop_id','=',$shop_id)->count();
        //预约人数
        $reservations = Db::table('fa_reservations')
            ->where('start_time', '<', $start_time)
            ->where('end_time', '>', $end_time)
            ->where('shop_id', '=', $shop_id)
            ->where('room_id', '=', $room_id)
            ->where('deposit_status', '=', 1)
            ->where('reservation_status','<>',2)
            ->value('(number_of_people-number_used)')?? 0; // 获取正在进行的预约
        return $incount+$reservations;
    }
}